home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / asmlib30.zip / DISK.DOC < prev    next >
Text File  |  1993-04-08  |  13KB  |  444 lines

  1.  
  2. ***************************** DISK & FILE *******************************
  3.  
  4. ASMLIB disk & file subroutines (c) Copyright 1991 Douglas Herr
  5. All rights reserved
  6.  
  7. The MS-DOS file attribute byte tells you whether a file is read-only,
  8. system, a subdirectory, or may provide other information.  File attribute
  9. bits may be combined.  Each bit of the file attribute means:
  10.  
  11.         0 = normal files
  12.         1 = read-only
  13.         2 = hidden files
  14.         4 = system files
  15.         8 = volume label (only one per disk)
  16.        16 = subdirectories
  17.        32 = archive bit set
  18.  
  19.    Thus a file with an attribute of 18 is a hidden subdirectory (16 OR 2)
  20.  
  21. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  22.  
  23. DISKWP:      determines if a floppy disk is write-protected
  24. Source:      diskwp.asm
  25.  
  26. Call with:   DL = floppy disk number (drive A: = 0)
  27. Returns:     AL = BIOS error code
  28.                 0 = no error
  29.                 1 = invalid disk number
  30.                 3 = disk is write-protected
  31.               128 = drive not ready
  32. Uses:        AX, flags
  33. Example:
  34.  
  35. include asm.inc
  36.  
  37. public  mycode
  38. extrn   diskwp:proc
  39.  
  40. .code
  41. diskwp  proc
  42.         .
  43.         .
  44.         .
  45.         mov     dl,1        ; drive B:
  46.         call    diskwp      ; can I write to this disk?
  47.         or      al,al
  48.         jz      no_problem
  49.  
  50.  
  51.  
  52. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  53.  
  54. FCOPY:       copy a file
  55. FCOPYM:      copy a file using supplied memory buffer
  56. Source:      fcopy.asm
  57.  
  58. Call with:   DS:[SI] = address of source filename
  59.              ES:[DI] = address of destination filename
  60.              Both filenames must be ASCIIZ strings.  Drive and path need
  61.              not be fully specified; filenames may not include * or ?
  62.              wildcards.
  63.              FCOPY only: Requires 64k DOS memory available
  64.              FCOPYM only: AX = segment address of 64k buffer
  65. Returns:     if CF = 0, no problem
  66.              if CF = 1, AX = DOS error code (AX = -1 if insufficient memory)
  67. Uses:        AX, CF
  68. Example:
  69.  
  70. .data
  71.         db 'b:'
  72. source  db 'asmlib.lib',0         ; copy the library to b:
  73.  
  74. extrn   fcopy:proc
  75. .code
  76. ; program fragment assumes DS:@data
  77.         .
  78.         .
  79.         push    ds
  80.         pop     es
  81.         assume es:@data
  82.         lea     si,source
  83.         mov     di,si                ; DI also points to source
  84.         sub     di,2                 ; back the pointer to the 'B:'
  85.         call    fcopy
  86.         jc      oops
  87.  
  88.  
  89.  
  90. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  91.  
  92. FCOUNT:      counts the number of files matching an ASCIIZ filespec string.
  93.              The filespec string may include the '*' and '?' wildcards.
  94. Source:      fcount.asm
  95.  
  96. Call with:   DS:[DX] pointing to filespec string
  97.              CX = file attributes
  98.              assumes DS:@data
  99. Returns:     AX = number of files matching the filespec string
  100. Uses:        AX, all other registers and flags are saved
  101. Example:
  102.  
  103. .code
  104. ; program fragment assumes DS:@data
  105.         .
  106.         .
  107.         .
  108.         lea    dx,filespec      ; address of filespec string
  109.         xor    cx,cx            ; normal files only
  110.         call   fcount
  111.  
  112.  
  113. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  114.  
  115. FEXIST:      determines if a file exists and can be opened with read access
  116. Source:      fexist.asm
  117.  
  118. Call with:   DS:[DX] pointing to ASCIIZ filename
  119. Returns:     if CF = 0, file exists
  120.              if CF = 1, AX = MS-DOS error code
  121. Uses:        AX, CF; all other flags and registers are saved
  122. Example:
  123.  
  124. include  asm.inc
  125.  
  126. extrn    fexist:proc
  127. .data
  128.  
  129. filename db 'asmlib.doc',0
  130.  
  131. .code
  132. ; program fragment assumes DS:@data
  133.          .
  134.          .
  135.          .
  136.          lea   dx,filename
  137.          call  fexist
  138.          jnc   got_the_file      ; if CF = 0, go on
  139.          jmp   doserror          ; else go to error handling code
  140.  
  141.  
  142.  
  143. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  144.  
  145. FFLUSH:      flushes the DOS output buffer for specified handle
  146. Source:      fflush.asm
  147.  
  148. Call with:   BX = file handle
  149.              flushing the buffer guards against data loss in case of system
  150.              failure, such as power loss
  151. Returns:     if CF = 0, no error; function successful
  152.              if CF = 1, AX = DOS error code
  153. Uses:        AX, flags
  154. Example:
  155.  
  156. include asm.inc
  157.  
  158. extrn fflush:proc
  159.  
  160. .code
  161. ; program opens file & writes to file
  162.       .
  163.       .
  164.       mov    bx,handle
  165.       call   fflush
  166.  
  167.  
  168.  
  169. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  170.  
  171. FGETSTR:     read an ASCII string from an open file
  172. Source:      fgetstr.asm
  173.  
  174. Call with:   BX = file handle
  175.              ES:[DI] pointing to memory buffer
  176.              CX = byte length of buffer
  177.              ASCII strings may be terminated with either 0Dh or 0Dh+0Ah.
  178.              After reading each string, FGetStr positions the file pointer
  179.              to read the next string.  The memory buffer should be at
  180.              least 2 bytes longer than the longest string you expect to
  181.              read.
  182. Returns:     if CF = 0, CX = length of ASCII string
  183.                      if CX = byte length of buffer, string >= size of buffer
  184.              if CF = 1, AX = DOS error code
  185.                      if AX = 0, you've reached the end of the file
  186. Uses:        AX, CX, CF; all other registers and flags are saved
  187. Example:
  188.  
  189. include   asm.inc
  190.  
  191. extrn     fgetstr:proc
  192.  
  193. .data
  194. strbuffer db 102 dup (0)         ; maximum string length is 100
  195.  
  196. .code
  197. ; program opens file with read or read/write access
  198.           .
  199.           .
  200.           .
  201.           mov   bx,file_handle
  202.           mov   cx,102          ; buffer size
  203.           push  ds
  204.           pop   es              ; ES = DS
  205.           lea   di,strbuffer    ; ES:[DI] points to start of buffer
  206.           call  fgetstr
  207.           jc    oops
  208.           mov   bx,di           ; minor parameter juggling
  209.           call  strndup         ; make a copy in near heap so I can re-use
  210.                                 ; the buffer
  211.           .
  212.           .
  213.           .
  214.  
  215.  
  216.  
  217. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  218.  
  219. FILELIST:    creates a list of file names matching a filespec mask
  220. Source:      filelist.asm (fcount.asm, dosalloc.asm)
  221.  
  222. Call with:   DS:[SI] pointing to filespec mask
  223.              CX = file attribute mask
  224. Returns:     if CF = 0:
  225.                ES = base segment address of list buffer
  226.                AX = number of filenames in list
  227.                CX = list field width
  228.              if CF = 1, AX = MS-DOS error code
  229.              You should use DOS function 49h to release the file list
  230.              buffer when you're done with it.
  231. Uses:        AX, CX, ES, CF
  232. Example:
  233.  
  234. include asm.inc
  235.  
  236. public  myproc
  237.  
  238. .data
  239. filespec db '*.*',0
  240.  
  241. .code
  242. ; program fragment assumes DS:@data
  243.         .
  244.         .
  245.         .
  246.         lea    si,filespec
  247.         mov    cx,16            ; normal files and subdirectories
  248.         call   filelist
  249.         jc     cant_do_it       ; oops
  250.  
  251.  
  252.  
  253. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  254.  
  255. FINDDATE:    given a successful call to FindFirst or FindNext, returns
  256.              the file's date stamp
  257. Source:      findfile.asm
  258.  
  259. Call with:   DS:[BX] pointing to DTA buffer; assumes DS  @DATA
  260. Returns:     DX = month
  261.              AX = day
  262.              CX = year
  263. Uses:        AX, CX, DX, flags
  264. Example:
  265.  
  266. .code
  267. ; program fragment assumes DS:@data
  268.         .
  269.         .
  270.         .
  271.         lea    bx,filespec
  272.         mov    cx,0              ; normal files only
  273.         call   findfirst         ; find first matching file
  274.         jc     no_more_files
  275.         cmp    ax,-1
  276.         je     no_more_files
  277.         call   finddate
  278.  
  279.  
  280.  
  281. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  282.  
  283. FINDFIRST:   This subroutine, when used with FindNext, finds files on
  284.              a disk which match an ASCIIZ filespec string.  The filespec
  285.              string may contain the '*' and '?' wildcards.
  286. Source:      findfile.asm (heap.asm)
  287.  
  288. Call with:   DS:[BX] pointing to ASCIIZ filespec string; assumes DS:@data
  289.              CX = file attribute mask
  290.  
  291.              FindFirst allocates space for a local DTA buffer from the
  292.              near heap.  See FindNext; also see HINIT.
  293.  
  294. Returns:     AX = error code
  295.              -1 = insufficient memory in near heap (128 bytes required)
  296.              0 = no error
  297.              CF = 1 if no files match the filespec string
  298.              DS:[BX] -> DTA buffer if the subroutine is successful.  Do not
  299.              alter the 128 bytes in the DTA buffer.
  300.              The name of the file is an ASCIIZ string at 30[BX]
  301.              The file attribute is a byte at 21[BX]
  302.              The low word of the file's size is at 26[BX]
  303.              The high word of the file's size is at 28[BX]
  304. Uses:        AX, BX, flags
  305. Example:
  306.  
  307. .code
  308. ; program fragment assumes DS:@data
  309.      .
  310.      .
  311.      .
  312.      lea    bx,filespec
  313.      mov    cx,0              ; normal files only
  314.      call   findfirst         ; find first matching file
  315.      jc     no_more_files
  316.      cmp    ax,-1
  317.      je     no_memory         ; memory not available
  318.  
  319. ; print the filename on the screen
  320. tprint_next:
  321.      mov    si,bx
  322.      add    si,30             ; point to filename in DTA buffer
  323.      mov    dh,count          ; row value
  324.      mov    dl,0              ; column 0
  325.      mov    ah,12             ; color attribute - RED!
  326.      call   tprint            ; display the file name on the screen
  327.      inc    count             ; next filename on next row
  328.      call   findnext          ; any more matching filenames?
  329.      jnc    tprint_next
  330. no_more_files:
  331.  
  332. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  333.  
  334. FINDNEXT:    finds file matching search string; use after FindFirst.
  335.              used only after a successful call to FindFirst.
  336. Source:      findfile.asm (heap.asm)
  337.  
  338. Call with:   no parameters; assumes DS:@data
  339.  
  340.              FindNext de-allocates the DTA buffer space after the first
  341.              unsuccessful search for a matching file.
  342.  
  343. Returns:     DS:[BX] -> DTA buffer
  344.              CF = 1 if no more files match the filespec string.
  345. Uses:        BX, flags
  346. Example:     see FindFirst.
  347.  
  348.  
  349. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  350.  
  351. FINDTIME:    given a successful call to FindFirst or FindNext, returns
  352.              the file's time stamp
  353. Source:      findfile.asm
  354.  
  355. Call with:   DS:[BX] pointing to DTA buffer; assumes DS:@data
  356. Returns:     DX = hour
  357.              AX = minute
  358.              CX = second
  359. Uses:        AX, CX, DX, flags
  360. Example:     lea    bx,filespec
  361.              mov    cx,0              ; normal files only
  362.              call   findfirst         ; find first matching file
  363.              jc     no_more_files
  364.              cmp    ax,-1
  365.              je     no_more_files
  366.              call   findtime
  367.  
  368.  
  369.  
  370. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  371.  
  372. FPUTCR:      writes a CR+LF pair to a file at the current position in
  373.              the file; the file must have been opened with read or
  374.              read/write access
  375. Source:      fputcr.asm
  376.  
  377. Call with:   BX = file handle
  378. Returns:     if CF = 1, AX = MS-DOS error code
  379.              if CF = 0, no error
  380. Uses:        AX, flags
  381. Example:     mov    bx,handle
  382.              call   fputcr
  383.  
  384.  
  385. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  386.  
  387. FSIZE:       determines a file's size
  388. Source:      fsize.asm
  389.  
  390. Call with:   BX = valid file handle
  391. Returns:     if CF = 0, DX:AX = file size (low word in AX)
  392.              if CF = 1, AX = MS-DOS error code
  393. Uses:        AX, DX, CF
  394. Example:
  395.  
  396. include asm.inc
  397.  
  398. extrn   fsize:proc
  399.  
  400. .data
  401. filenam db 'ASMLIB.DOC',0      ; ASCIIZ filename
  402.  
  403. .code
  404.         .
  405.         .
  406.         .
  407.         lea     dx,filenam     ; point to filename
  408.         mov     ax,3D00h       ; MS-DOS open file function, read-only
  409.         int     21h
  410.         jc      oops           ; jump to error control
  411.                                ; else no problem - continue
  412.         mov     bx,ax          ; file handle in BX
  413.         call    fsize
  414.  
  415.  
  416. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  417.  
  418. QFNAME:      qualifies a filename
  419. Source:      qfname.asm
  420.  
  421. Call with:   DS:[BX] pointing to a filename; the filename may contain
  422.              drive specification and/or complete or partial path name.
  423.              Drive specification and path name not required.
  424. Returns:     DS:[SI] pointing to the full DRIVESPEC:\PATH\FILENAME
  425.              CX = length of full filename
  426.              Note that DS:[SI] points to QFName's buffer space; the next
  427.              call to QFName will return a new filename at the same address.
  428. Uses:        SI, CX, flags
  429. Example:
  430.  
  431. include asm.inc
  432.  
  433. .data
  434. docs   db '*.doc',0         ; search for .DOC files in current directory
  435.  
  436. .code
  437. ; program fragment assumes DS:@data
  438.        .
  439.        .
  440.        .
  441.        lea    bx,docs
  442.        call   qfname
  443.  
  444.